Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@streamparser/json

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@streamparser/json

Streaming JSON parser in Javascript for Node.js, Deno and the browser

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
485K
decreased by-12.42%
Maintainers
1
Weekly downloads
 
Created

What is @streamparser/json?

@streamparser/json is a streaming JSON parser for Node.js that allows you to process JSON data as it is being received, rather than waiting for the entire JSON payload to be available. This can be particularly useful for handling large JSON files or streams of JSON data from APIs.

What are @streamparser/json's main functionalities?

Streaming JSON Parsing

This feature allows you to parse JSON data as it is being received. The `onValue` event is triggered whenever a complete JSON value is parsed.

const { parser } = require('@streamparser/json');

const jsonParser = new parser();

jsonParser.onValue = (value) => {
  console.log('Parsed value:', value);
};

jsonParser.write('{"key": "value"}');
jsonParser.end();

Handling Large JSON Files

This feature demonstrates how to handle large JSON files by streaming the file content and parsing it chunk by chunk. This avoids loading the entire file into memory.

const fs = require('fs');
const { parser } = require('@streamparser/json');

const jsonParser = new parser();

jsonParser.onValue = (value) => {
  console.log('Parsed value:', value);
};

const readStream = fs.createReadStream('largeFile.json');
readStream.on('data', (chunk) => {
  jsonParser.write(chunk);
});
readStream.on('end', () => {
  jsonParser.end();
});

Streaming JSON from an API

This feature shows how to parse streaming JSON data from an API. The JSON data is processed as it is received, making it efficient for handling large or continuous streams of data.

const https = require('https');
const { parser } = require('@streamparser/json');

const jsonParser = new parser();

jsonParser.onValue = (value) => {
  console.log('Parsed value:', value);
};

https.get('https://api.example.com/streaming-json', (res) => {
  res.on('data', (chunk) => {
    jsonParser.write(chunk);
  });
  res.on('end', () => {
    jsonParser.end();
  });
});

Other packages similar to @streamparser/json

FAQs

Package last updated on 27 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc